package com.yl.rabbitmq.day02;

import com.rabbitmq.client.Channel;
import com.yl.rabbitmq.utils.RabbitMQUtil;

import java.util.Scanner;

/**
 * @author yangl
 * 生产者，可以发送大量的消息
 */
public class Producer02 {
    /**
     * 队列名称
     */
    public static final String QUEUE_NAME = "hello";

    public static void main(String[] args) throws Exception{
        Channel channel = RabbitMQUtil.getChannel();
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        //从控制台接收消息
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String message = scanner.next();
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
            System.out.println("发送消息完成：" + message);
        }
    }
}
